package mxp

fun rom2logisim(rom: Array<Int>): String {
    val str = StringBuilder()
    str.append("v2.0 raw\n")
    var n = 0
    var wrap = 0
    for (i in 0 until rom.size) {
        if (rom[i] == 0) {
            n++
        } else {
            if (n > 0) {
                str.append(String.format("%d*0 ", n))
                n = 0
                if (++wrap == 16) {
                    str.append('\n')
                    wrap = 0
                }
            }
            str.append(String.format("%x ", rom[i]))
            if (++wrap == 16) {
                str.append('\n')
                wrap = 0
            }
        }
    }
    return str.toString()
}